package org.openrbac.rbac.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.openrbac.rbac.entity.Role;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import java.util.List;

/**
* @author bapie
* @description 针对表【role(角色表)】的数据库操作Mapper
* @createDate 2024-04-03 15:37:15
* @Entity org.openrbac.entity.Role
*/
public interface RoleMapper extends BaseMapper<Role> {
    /**
     * 根据角色ID删除权限
     * @param roleId 角色ID
     * @return boolean
     */
    @Delete("delete from role_auth where role_id=#{roleId}")
    boolean deleteAuthsByRoleId(@Param("roleId") Long roleId);

    /**
     * 批量插入角色和权限
     * @param roleId 角色ID
     * @param authIds 权限IDS
     * @return boolean
     */
    @Insert("<script>" +
            "insert role_auth(role_id, auth_id) values " +
            "<foreach collection='authIds' item='item' separator=','>" +
            "   (#{roleId},#{item})" +
            "</foreach>" +
            "</script>")
    boolean insertRolesBatch(@Param("roleId") Long roleId, @Param("authIds") List<Long> authIds);
}




